<!--
 * @Description: 
 * @Version: 1.0
 * @Author: wenbin
 * @Date: 2021-03-23 13:29:20
 * @LastEditors: wenbin
 * @LastEditTime: 2021-08-11 10:42:06
 * @FilePath: /magus-plugin/examples/App.vue
 * Copyright (C) 2021 wenbin. All rights reserved.
-->
<template>
  <div id="app">
    <!-- <magus-layout
      :headerInfo="headerInfo"
      :badgeValue="badgeValue"
      @activeSubMenu="activeDropdown(datas)"
      v-if="$route.meta.isNeedLayout"
    >
      <router-view />
    </magus-layout> -->
    <component
      :headerInfo="headerInfo"
      :badgeValue="badgeValue"
      @activeFun="activeFun"
      v-if="$route.meta.isNeedLayout"
      :is="componentName"
    >
      <router-view />
    </component>
    <!-- <magus-horizontal-layout
      :headerInfo="headerInfo"
      :badgeValue="badgeValue"
      v-if="$route.meta.isNeedLayout"
    >
      <router-view />
    </magus-horizontal-layout> -->
    <router-view v-else />
  </div>
</template>

<script>
import appsApi from "./api/auth";
import dictsApi from "./api/dicts";
import { mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters({
      menu: "platform/menu",
    }),
  },
  data() {
    return {
      headerInfo: {
        imgUrl: require("./assets/images/logo.png"),
        // 没有图片显示文字
        logoText: "MagusCloud",
        // logo详细描述
        logoDetail: "上海麦杰科技股份有限公司",
        // 一级菜单
        menuList: [],
        otherMenu: [
          {
            name: "退出登陆",
          },
        ],
      },
      // componentName: "magus-horizontal-layout",
      componentName: "magus-layout",
    };
  },
  created() {
    this.$magusCloudApi.catchUtil.setLocalItem("theme", "blue");
    this.$magusCloudApi.commonUtils.toggleClass(document.body, `magus-ui-blue`);
    // this.$magusCloudApi.catchUtil.setLocalItem("theme", "technology-blue");
    // this.$magusCloudApi.commonUtils.toggleClass(
    //   document.body,
    //   `magus-ui-technology-blue`
    // );
    this.getDictionary();
  },
  mounted() {
    this.getApps();
    this.$store
      .dispatch("platform/GET_MENU_LIST", this.$magusCloudApi)
      .then((res) => {
        this.headerInfo.menuList = res.data;
        // if (res.data.length > 0) {
        //   this.$magusCloudApi.catchUtil.setLocalItem(
        //     "activeMenu",
        //     JSON.stringify(res.data[0])
        //   );
        //   let subMenu = res.data[0].children;
        //   if (subMenu.length) {
        //     this.$magusCloudApi.catchUtil.setLocalItem(
        //       "activeSubMenu",
        //       JSON.stringify(subMenu[0])
        //     );
        //     if (subMenu[0].extend && subMenu[0].extend.uri) {
        //       if (window.__POWERED_BY_QIANKUN__) {
        //         this.$router.push({
        //           path: subMenu[0].extend.appUri + subMenu[0].extend.uri,
        //           query: subMenu[0].extend.params
        //             ? JSON.parse(subMenu[0].extend.params)
        //             : {},
        //         });
        //       } else {
        //         this.$router.push({
        //           path: subMenu[0].extend.uri,
        //           query: subMenu[0].extend.params
        //             ? JSON.parse(subMenu[0].extend.params)
        //             : {},
        //         });
        //       }
        //     }
        //   }
        // }
      });
  },
  methods: {
    badgeValue(datas) {
      if (datas.text === "平台管理") {
        return "12";
      } else if (datas.text === "设备层级配置") {
        return "5";
      }
    },
    activeDropdown(datas) {
      console.log(datas);
    },
    activeFun(datas) {
      console.log(datas);
    },
    getDictionary() {
      this.$magusCloudApi.apiConfig.get(dictsApi.getDictCatch).then((res) => {
        this.$magusCloudApi.catchUtil.setLocalItem(
          "dictionary",
          JSON.stringify(res)
        );
      });
    },
    getApps() {
      this.$magusCloudApi.apiConfig
        .get(appsApi.getAllApp, {}, { test: "111111111" }, { timeout: 1 })
        .then((res) => {
          console.log(res);
        });
    },
  },
};
</script>

<style></style>
